import { Injectable } from '@angular/core';
import { InMemoryDbService } from 'angular-in-memory-web-api';
import { Hero } from './hero';

@Injectable({
  providedIn: 'root',
})
export class InMemoryDataService implements InMemoryDbService {
  createDb() {
    const heroes = [
      { id: 11, name: 'Galio' },
      { id: 12, name: 'Tristana' },
      { id: 13, name: 'JarvianIV' },
      { id: 14, name: 'Karma' },
      { id: 15, name: 'Lee sin' },
      { id: 16, name: 'Leona' },
      { id: 17, name: 'Monkey king' },
      { id: 18, name: 'Sejuani' },
      { id: 19, name: 'Shen' },
      { id: 20, name: 'XinZhao' },
    ];
    return {heroes}
  }
  genId(heroes: Hero[]): number{
    return heroes.length>0?Math.max(...heroes.map(hero=>hero.id))+1 : 11;
  }
  constructor() {}
}
